# coding:utf-8
from odoo import models, fields, api
from odoo.osv import expression


class OLResPartner(models.Model):
    _inherit = 'res.partner'

    purchase_user_id = fields.Many2one('res.users', string='Buyer')
    department_id = fields.Many2one('hr.department', string='Department')

    @api.onchange('purchase_user_id')
    def onchange_purchase_user_id(self):
        self.department_id = self.purchase_user_id \
                             and self.purchase_user_id.employee_ids \
                             and self.purchase_user_id.employee_ids[0].department_id \
                             and self.purchase_user_id.employee_ids[0].department_id.id or False

